import sys


def iteDemo():
    list = [1, 2, 4, 5, 6, 7, 8, 9, 10]
    hasvalue = iter(list)
    a = next(hasvalue)
    print(a)
    print("=======")
    for it in hasvalue:
        print(it)


def iteDemo1():
    list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    hasvalue = iter(list)
    while True:
        try:
            print(next(hasvalue))
        except StopIteration:
            sys.exit()


# 生成器函数 - 斐波那契
def fibonacci(n):
    a, b, count = 0, 1, 0
    while True:
        if count > n:
            return
        yield a
        a, b = b, a + b
        count += 1


f = fibonacci(10)
for a in f:
    print(a)
